/* GNOME CSD styles for headerbar on Firefox  */

@namespace xul url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

:root[tabsintitlebar], :root[customtitlebar] {
/* Headerbar top border corners rounded */
&:root[sizemode="normal"]:not([gtktiledwindow="true"]) {
  #nav-bar {
    border-top-left-radius: env(-moz-gtk-csd-titlebar-radius, 12px) !important;
    border-top-right-radius: env(-moz-gtk-csd-titlebar-radius, 12px) !important;
    box-shadow: var(--gnome-headerbar-box-shadow) !important;
  }

  #nav-bar:-moz-window-inactive {
    box-shadow: var(--gnome-inactive-headerbar-box-shadow) !important;
  }

  /* stylelint-disable-next-line media-query-no-invalid */
  @media (-moz-bool-pref: "widget.gtk.rounded-bottom-corners.enabled") {
    body,
    dialog,
    body::backdrop,
    dialog::backdrop {
      /* Use an uniform clip to allow WebRender to optimize it better */
      border-radius: env(-moz-gtk-csd-titlebar-radius, 12px) !important;
    }

    window[role="dialog"] {
      border-bottom-left-radius: env(-moz-gtk-csd-titlebar-radius, 12px) !important;
      border-bottom-right-radius: env(-moz-gtk-csd-titlebar-radius, 12px) !important;
    }
  }
}

/* Always show nav bar window buttons*/
#nav-bar > .titlebar-buttonbox-container {
	display: flex !important;
}

#toolbar-menubar, #TabsToolbar {
	/* Always hide menu bar window buttons*/
	& > .titlebar-buttonbox-container {
		display: none !important;
	}
}

#nav-bar, #titlebar {
	/* Window buttons box */
	.titlebar-buttonbox-container,
	#titlebar-buttonbox-container {
		-moz-appearance: none !important;
		padding: 0 3px 0 4px;
		position: absolute !important;
		right: 8px;
		top: 0;
		display: block !important;
	}

	.titlebar-buttonbox {
		-moz-appearance: none !important;
	}

	/* Window buttons style */
	.titlebar-button {
		-moz-appearance: none !important;
		border: none !important;
		border-radius: 100px !important;
		height: 16px;
		width: 16px;
		margin: 16px 4px !important;
		padding: 2px 0 !important;
		--inactive-titlebar-opacity: 1 !important;
	}

	&, &:-moz-window-inactive {
		.titlebar-button .toolbarbutton-icon {
			opacity: 0 !important;
			appearance: none !important;
		}

		.titlebar-button[disabled="true"] {
			opacity: 0.35 !important;
		}
	}
}


/* Fullscreen headerbar */
&:root[inFullscreen] {
	/* Fullscreen headerbar padding for 1 button */
	#nav-bar {
		padding-right: 50px !important;
	}

	#nav-bar .titlebar-button,
	#titlebar .titlebar-button {
		height: 24px;
		width: 24px;
		margin: 12px 4px !important;
		padding: 0 !important;
	}

	/* Remove close and minimize buttons from fullscreen buttons */
	#window-controls #close-button,
	#window-controls #minimize-button,
	#titlebar .titlebar-buttonbox .titlebar-close,
	#titlebar .titlebar-buttonbox .titlebar-min,
	#nav-bar .titlebar-buttonbox .titlebar-close,
	#nav-bar .titlebar-buttonbox .titlebar-min {
		display: none !important;
	}
}
}


/* Window buttons: at least 1 button */
@media (-moz-gtk-csd-minimize-button), (-moz-gtk-csd-maximize-button), (-moz-gtk-csd-close-button) {
:root[tabsintitlebar], :root[customtitlebar] {
	&:root:not([inFullscreen]) #nav-bar {
		padding-right: 50px !important;
	}
}
}
/* Window buttons: at least 2 buttons */
@media (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button),
       (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-close-button),
       (-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button) {
       :root[tabsintitlebar], :root[customtitlebar] {
	&:root:not([inFullscreen]) #nav-bar {
		padding-right: 70px !important;
	}
	}
}
/* Window buttons: 3 buttons */
@media (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button) {
:root[tabsintitlebar], :root[customtitlebar] {
	&:root:not([inFullscreen]) #nav-bar {
		padding-right: 96px !important;
	}
}
}

/* Left window buttons */
@media (-moz-gtk-csd-reversed-placement) {
	:root[tabsintitlebar], :root[customtitlebar] {
	&:root:not([inFullscreen]) #nav-bar {
		padding-right: 6px !important;
	}

	/* Window buttons box */
	#nav-bar .titlebar-buttonbox-container,
	#titlebar .titlebar-buttonbox-container {
		padding: 0 3px 0 4px;
		left: 8px;
		right: auto;
	}

	/* Fullscreen headerbar padding for 1 button */
	&:root[inFullscreen] #nav-bar {
		padding-left: 50px !important;
	}
	}

	/* Window controls: at least 1 button */
	@media (-moz-gtk-csd-minimize-button), (-moz-gtk-csd-maximize-button), (-moz-gtk-csd-close-button) {
	:root[tabsintitlebar], :root[customtitlebar] {
		&:root:not([inFullscreen]) #nav-bar {
			padding-left: 50px !important;
		}
	}
	}
	/* Window controls: at least 2 buttons */
	@media (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button),
		(-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-close-button),
		(-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button) {
		:root[tabsintitlebar], :root[customtitlebar] {
		&:root:not([inFullscreen]) #nav-bar {
			padding-left: 70px !important;
		}
		}
	}
	/* Window controls: 3 buttons */
	@media (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button) {
		:root[tabsintitlebar], :root[customtitlebar] {
		&:root:not([inFullscreen]) #nav-bar {
			padding-left: 96px !important;
		}
		}
	}
}

/* Remove tabsbar titlebar blank spaces */
#TabsToolbar .titlebar-placeholder {
	display: none !important;
}

/* Prevent menubar from breaking */
#toolbar-menubar:not([inactive=true]) {
	height: 30px !important;
	margin-bottom: 8px;
}

/* Remove default style of titlebar */
#titlebar {
	-moz-appearance: none !important;
}

/* Fix the issue when dragging tabs */
#navigator-toolbox[movingtab] #TabsToolbar {
	padding-bottom: 0 !important;
}
